﻿using AiChiTu.TraceabilitySystem.ErrorCode.Extensions;

namespace AiChiTu.TraceabilitySystem.ErrorCode
{
	/// <summary>
	/// 公共响应结果
	/// </summary>
	public class APIResult <T>
	{
		/// <summary>
		/// 返回码
		/// </summary>
		public ResultCode Code { get; set; }
		/// <summary>
		/// 消息
		/// </summary>
		public string Message { get; set; }
		/// <summary>
		/// 数据
		/// </summary>
		public T? Data { get; set; }
		///// <summary>
		///// 构造方法
		///// </summary>
		///// <param name="code">返回码</param>
		///// <param name="mes">消息</param>
		///// <param name="data">数据</param>
		//public APIResult(ResultCode code,string mes,T? data)
		//{
		//	this.Code = code;
		//	this.Message = mes;
		//	this.Data = data;
		//}
		/// <summary>
		/// 带返回值的响应结果
		/// </summary>
		/// <param name="resultCode">返回码</param>
		/// <param name="t">泛型</param>
		/// <returns>返回任务</returns>
		public static APIResult<T> Result(ResultCode resultCode,T? t)
		{
			return new APIResult<T>()
			{
				Code = resultCode,
				Message = resultCode.GetDescription(),
				Data = t
			};
		}
		/// <summary>
		/// 无返回值的响应结果
		/// </summary>
		/// <param name="resultCode">返回码</param>
		/// <returns>返回任务</returns>
		public static APIResult<T> Result(ResultCode resultCode)
		{
			return new APIResult<T>()
			{
				Code = resultCode,
				Message = resultCode.GetDescription(),
			};
		}
	}
}
